<?php

class Core_Backend_Component_Promotion_View_Ad_Index extends Core_Backend_Share_View_Grid {

    protected function buildToolbar($toolbar) {
        parent::buildToolbar($toolbar);
        if ($this->getIdentity()->isAllowAction('promotion_ad_review')) {
            $group = $toolbar->createGroup('status');
            $group->addButton($this->__('share.button.publish'))
                    ->bindEvent('click', "submitGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(array('status'=>'published'), 'review') . "')");
            $group->addButton($this->__('share.button.forbid'))
                    ->bindEvent('click', "forbidGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(array('status'=>'forbidden'), 'review') . "')");
        }
        $group = $toolbar->createGroup();
        $group->addLink($this->getUrl(NULL, 'create'), $this->__('share.button.create'));
    }

    public function buildGrid($grid) {
        $grid->setId('ad_grid')
                ->setPrimaryKey('id')
                ->setSortField($this->getRequest()->getQuery('sort', 'id'))
                ->setSortDirection($this->getRequest()->getQuery('dir', 'asc'))
                ->setSortUrlFormat($this->getSortUrl());
        $grid->addLabelColumn($this->__('share.label.title'), 'title', '{title}')
                ->setSortField('title');
        $grid->addLabelColumn($this->__('share.label.url'), 'url', '{url}')
                ->setSortField('url');
        $grid->addLabelColumn($this->__('promotion.ad.type'), 'type', '{type}');
        $grid->addLabelColumn($this->__('share.label.start_time'), 'starttime', '{start_time}');
        $grid->addLabelColumn($this->__('share.label.end_time'), 'endtime', '{end_time}');
        $grid->addLabelColumn($this->__('share.label.position'), 'positionname', '{position_name}');
        $grid->addLabelColumn($this->__('share.label.status'), 'status', '{{lang "status.publication.{status}"}}');
        $grid->addLinkColumn('#', 'edit', $this->getUrl(array('id' => '{id}'), 'edit'), $this->__('share.button.edit'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->setDataSource($this->getList()->toArray());
        parent::buildGrid($grid);
    }

    protected function buildPagination($pagination) {
        $pagination->setUrlFormat($this->getPaginationUrl())->setRecordCount($this->getRecords());
        parent::buildPagination($pagination);
    }

}

